#include "Encoding/Unicode.h"
#include "Encoding/UTF8.h"
#include "FileTest.h"

using namespace SystemTool;
using namespace SystemTool::IO;
using namespace SystemTool::Encoding;

int TestFile()
{
	try
	{
		std::string strFilePath = "";

		/*if (!File::Create(strFilePath))
		{
			return -3;
		}*/

		/*std::string strDestFilePath = "";

		if (!File::Copy(strFilePath, strDestFilePath))
		{
			return -2;
		}*/

		/*unsigned long long iFileSize = File::GetFileSize(strFilePath);

		File::Delete(strFilePath);*/

		//File::Rename(strFilePath, "E:/12/1/55.jmx");

		File FileHelper;

		if (!FileHelper.Open(strFilePath, FILE_READ))
		{
			return -4;
		}

		FileHelper.Seek(FILE_SEEK_BEGIN, 2);

		char buffer[1024] = { 0 };

		FileHelper.Read(buffer, 1024);

		std::string strData = buffer;

		std::wstring strFinalData = Unicode::GetGbkString(strData, ENCODE_UTF8);

		FileHelper.Close();

		if (!FileHelper.Open(strFilePath, FILE_APPEND))
		{
			return -5;
		}

		std::string strTestData = "";

		std::string strUtf8Data = UTF8::GetString(strFinalData, ENCODE_GBK);

		FileHelper.Write(strUtf8Data.c_str(), strUtf8Data.length());

		FileHelper.Close();
	}
	catch (BSException& e)
	{
		std::cout << e.ErrorMsg() << std::endl;

		return -1;
	}

	return 0;
}
